//
// Created by 32827 on 2023/12/2.
//

#ifndef YZFRAME_YZ_I2C_MPU6050_H
#define YZFRAME_YZ_I2C_MPU6050_H
//参考 https://blog.csdn.net/qq_60521516/article/details/123757041
#include "yz.h"
#include "yzl_conf.h"
#define YZL_MPU6050_ADDRESS 0b1101000
#define YZL_MPU6050_ADDRESS_2 0b1101001

#define YZL_MPU6050_WHOIS 0x75

#define YZL_MPU6050_REG_POWER1_ADDRESS 0x6B
#define YZL_MPU6050_REG_POWER1_RESET_VALUE 0b10000000
#define YZL_MPU6050_REG_POWER1_CLK_VALUE 0b00000001

#define YZL_MPU6050_REG_POWER2_ADDRESS 0x6C
///无待机和低功耗模式
#define YZL_MPU6050_REG_POWER2_RESET_VALUE 0b00000000

///中断控制寄存器
#define YZL_MPU6050_REG_INT_ADDRESS 0x38
#define YZL_MPU6050_REG_INT_CLOSE_VALUE 0x00

///采样频率
#define YZL_MPU6050_REG_SIMPLE_RATE_ADDRESS 0x19
#define YZL_MPU6050_REG_SIMPLE_RATE_MOST_VALUE 0x007

///低通滤波设置
#define YZL_MPU6050_REG_DLPF_ADDRESS  0x1A
#define YZL_MPU6050_REG_DLPF_NORMAL_SET_VALUE 0x04

///陀螺仪配置(角速度)
#define YZL_MPU6050_REG_GYROSCOPE_ADDRESS 0x1B
#define YZL_MPU6050_REG_GYROSCOPE_NORMAL_SET_VALUE 0x18

///加速度配置
#define YZL_MPU6050_REG_ACCELEROMETER_ADDRESS 0x1C
#define YZL_MPU6050_REG_ACCELEROMETER_NORMAL_SET_VALUE 0x08

///INT 引脚/旁路配置
#define YZL_MPU6050_REG_INT_PIN_CFG_ADDRESS 0x37
#define YZL_MPU6050_REG_INT_PIN_CFG_NORMAL_SET_VALUE 0x02

///加速度相关寄存器
#define YZL_MPU6050_REG_ACCELEROMETER_X_HIGH_ADDRESS 0x3B
#define YZL_MPU6050_REG_ACCELEROMETER_X_LOW_ADDRESS 0x3C
#define YZL_MPU6050_REG_ACCELEROMETER_Y_HIGH_ADDRESS 0x3D
#define YZL_MPU6050_REG_ACCELEROMETER_Y_LOW_ADDRESS 0x3E
#define YZL_MPU6050_REG_ACCELEROMETER_Z_HIGH_ADDRESS 0x3F
#define YZL_MPU6050_REG_ACCELEROMETER_Z_LOW_ADDRESS 0x40
#define YZL_MPU6050_REG_ACCELEROMETER_X_ADDRESS 0x3B
#define YZL_MPU6050_REG_ACCELEROMETER_Y_ADDRESS 0x3D
#define YZL_MPU6050_REG_ACCELEROMETER_Z_ADDRESS 0x3F

///温度相关寄存器
#define YZL_MPU6050_REG_TEMPERATURE_HIGH_ADDRESS 0x41
#define YZL_MPU6050_REG_TEMPERATURE_LOW_ADDRESS 0x42
#define YZL_MPU6050_REG_TEMPERATURE_ADDRESS 0x41

///陀螺仪相关寄存器
#define YZL_MPU6050_REG_GYROSCOPE_X_HIGH_ADDRESS 0x43
#define YZL_MPU6050_REG_GYROSCOPE_X_LOW_ADDRESS 0x44
#define YZL_MPU6050_REG_GYROSCOPE_Y_HIGH_ADDRESS 0x45
#define YZL_MPU6050_REG_GYROSCOPE_Y_LOW_ADDRESS 0x46
#define YZL_MPU6050_REG_GYROSCOPE_Z_HIGH_ADDRESS 0x47
#define YZL_MPU6050_REG_GYROSCOPE_Z_LOW_ADDRESS 0x48
#define YZL_MPU6050_REG_GYROSCOPE_X_ADDRESS 0x43
#define YZL_MPU6050_REG_GYROSCOPE_Y_ADDRESS 0x45
#define YZL_MPU6050_REG_GYROSCOPE_Z_ADDRESS 0x47

YZF_BOOL yzl_mpu6050_check(YZF_I2C_POINTER i2c);
YZF_RESULT yzl_mpu6050_init(YZF_I2C_POINTER i2c);
YZF_RESULT yzl_mpu6050_read_acc(YZF_I2C_POINTER i2c,uint16_t *data);
YZF_RESULT yzl_mpu6050_read_gyro(YZF_I2C_POINTER i2c,uint16_t *data);
YZF_RESULT yzl_mpu6050_read_temperature(YZF_I2C_POINTER i2c,uint16_t *data);

#if USE_SOFT_PORT
#include "yzl_softport_i2c.h"
YZF_BOOL yzl_mpu6050_soft_check(YZL_Soft_I2C* i2c);
YZF_RESULT yzl_mpu6050_soft_init(YZL_Soft_I2C* i2c);
YZF_RESULT yzl_mpu6050_soft_read_acc(YZL_Soft_I2C* i2c,uint16_t *data);
YZF_RESULT yzl_mpu6050_soft_read_gyro(YZL_Soft_I2C* i2c,uint16_t *data);
YZF_RESULT yzl_mpu6050_soft_read_temperature(YZL_Soft_I2C* i2c,uint16_t *data);
#endif
#endif //YZFRAME_YZ_I2C_MPU6050_H
